<!DOCTYPE html>
<html lang="en">
<head><meta name="generator" content="Hexo 3.9.0">
    <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">

    <meta name="description" content="冯同学的博客">


    <meta name="keywords" content="冯同学的博客">


<title>如何集成腾讯Bugly | 冯同学的博客</title>



    <link rel="icon" href="/blog/favicon.ico">




    <!-- stylesheets list from _config.yml -->
    
    <link rel="stylesheet" href="/blog/css/style.css">
    



    <!-- scripts list from _config.yml -->
    
    <script src="/blog/js/script.js"></script>
   
  
    
    <script src="/blog/js/tocbot.min.js"></script>
   
  
    
    <script src="/blog/js/clicklove.js"></script>
   
  
    
    <script src="/blog/js/clicksocialvalue.js"></script>
   
  
    



    
    
        
    


</head>
<body>
    <div class="wrapper">
        <header>
    <nav class="navbar">
        <div class="container">
            <div class="navbar-header header-logo"><a href="/blog/">冯同学的Blog</a></div>
            <div class="menu navbar-right">
                
                    <a class="menu-item" href="/blog/archives">帖子</a>
                
                    <a class="menu-item" href="/blog/tag">标签</a>
                
                    <a class="menu-item" href="/blog/友链">友链</a>
                
                    <a class="menu-item" href="/blog/关于">关于</a>
                
                <input id="switch_default" type="checkbox" class="switch_default">
                <label for="switch_default" class="toggleBtn"></label>
            </div>

        </div>
    </nav>

    
    <nav class="navbar-mobile" id="nav-mobile">
        <div class="container">
            <div class="navbar-header">
                <div>
                    <a href="/blog/">冯同学的Blog</a><a id="mobile-toggle-theme">·&nbsp;Light</a>
                </div>
                <div class="menu-toggle" onclick="mobileBtn()">&#9776; Menu</div>
            </div>
            <div class="menu" id="mobile-menu">
                
                    <a class="menu-item" href="/blog/archives">帖子</a>
                
                    <a class="menu-item" href="/blog/tag">标签</a>
                
                    <a class="menu-item" href="/blog/友链">友链</a>
                
                    <a class="menu-item" href="/blog/关于">关于</a>
                
            </div>
        </div>
    </nav>

</header>
<script>

var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?763ce62c604e21949386b5a3e9533b17";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();

    var mobileBtn = function f() {
        var toggleMenu = document.getElementsByClassName("menu-toggle")[0];
        var mobileMenu = document.getElementById("mobile-menu");
        if(toggleMenu.classList.contains("active")){
           toggleMenu.classList.remove("active")
            mobileMenu.classList.remove("active")
        }else{
            toggleMenu.classList.add("active")
            mobileMenu.classList.add("active")
        }
    }
</script>
        <div class="main">
            <div class="container">
    
    
        <div class="post-toc">
    <div class="tocbot-list">
    </div>
    <div class="tocbot-list-menu">
        <a class="tocbot-toc-expand" onclick="expand_toc()">Expand all</a>
        <a onclick="go_top()">Back to top</a>
        <a onclick="go_bottom()">Go to bottom</a>
    </div>
</div>

<script>
    document.ready(
        function () {
            tocbot.init({
                tocSelector: '.tocbot-list',
                contentSelector: '.post-content',
                headingSelector: 'h1, h2, h3, h4, h5',
                collapseDepth: 1,
                orderedList: false,
                scrollSmooth: true,
            })
        }
    )

    function expand_toc() {
        var b = document.querySelector(".tocbot-toc-expand");
        tocbot.init({
            tocSelector: '.tocbot-list',
            contentSelector: '.post-content',
            headingSelector: 'h1, h2, h3, h4, h5',
            collapseDepth: 6,
            orderedList: false,
            scrollSmooth: true,
        });
        b.setAttribute("onclick", "collapse_toc()");
        b.innerHTML = "Collapse all"
    }

    function collapse_toc() {
        var b = document.querySelector(".tocbot-toc-expand");
        tocbot.init({
            tocSelector: '.tocbot-list',
            contentSelector: '.post-content',
            headingSelector: 'h1, h2, h3, h4, h5',
            collapseDepth: 1,
            orderedList: false,
            scrollSmooth: true,
        });
        b.setAttribute("onclick", "expand_toc()");
        b.innerHTML = "Expand all"
    }

    function go_top() {
        window.scrollTo(0, 0);
    }

    function go_bottom() {
        window.scrollTo(0, document.body.scrollHeight);
    }

</script>
    

    
    <article class="post-wrap">
        <header class="post-header">
            <h1 class="post-title">如何集成腾讯Bugly</h1>
            
                <div class="post-meta">
                    
                        作者: <a itemprop="author" rel="author">冯同学</a>
                    

                    
                        <span class="post-time">
                      &nbsp;&nbsp;日期: <a>三月 15, 2020&nbsp;&nbsp;15:04:01</a>
                        </span>
                    
                    
                </div>
            
        </header>

        <div class="post-content">
            <h1 id="Android-如何集成腾讯Bugly"><a href="#Android-如何集成腾讯Bugly" class="headerlink" title="[Android]如何集成腾讯Bugly"></a>[Android]如何集成腾讯Bugly</h1><ul>
<li><code>本文只为Android方面提供讲解</code></li>
</ul>
<h3 id="何为bugly"><a href="#何为bugly" class="headerlink" title="何为bugly"></a>何为bugly</h3><blockquote>
<p>腾讯Bugly，为移动开发者提供专业的异常上报和运营统计，帮助开发者快速发现并解决异常，同时掌握产品运营动态，及时跟进用户反馈。还可以通过bugly的更新组件，提供自动检查更新和应用下发。</p>
</blockquote>
<h3 id="需要用到的"><a href="#需要用到的" class="headerlink" title="需要用到的"></a>需要用到的</h3><p>Android开发工具(我使用的是Android studio)  </p>
<h3 id="开始集成"><a href="#开始集成" class="headerlink" title="开始集成"></a>开始集成</h3><ol>
<li>首先打开你需要集成bugly的项目，也可以新建一个TestDemo。</li>
<li>打开项目路径<code>app/build.gradle</code>，进行一些操作。</li>
</ol>
<ul>
<li>添加导入仓库。  </li>
</ul>
<p><em>至于这个仓库版本，你可以去bugly的<a href="https://bugly.qq.com/v2/downloads" target="_blank" rel="noopener">官网</a>]查看最新版本号。</em></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">dependencies &#123;</span><br><span class="line">   ***</span><br><span class="line">    //bugly</span><br><span class="line">    implementation &apos;com.tencent.bugly:crashreport_upgrade:1.4.2&apos;//版本号可以去官网查看</span><br><span class="line">    implementation &apos;com.tencent.bugly:nativecrashreport:3.7.1&apos;//版本号可以去官网查看</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>设置ndk兼容架构<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">android &#123;</span><br><span class="line">***</span><br><span class="line">    defaultConfig &#123;</span><br><span class="line"></span><br><span class="line">        //ndk支持架构</span><br><span class="line">        ndk &#123;</span><br><span class="line">            //设置支持的SO库架构。在集成Bugly SO库时，请注意只保留支持的架构SO库。</span><br><span class="line">            abiFilters &apos;armeabi&apos; , &apos;x86&apos;, &apos;armeabi-v7a&apos;, &apos;x86_64&apos;, &apos;arm64-v8a&apos;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h3 id="Bugly初始化"><a href="#Bugly初始化" class="headerlink" title="Bugly初始化"></a>Bugly初始化</h3><ol>
<li>为你的项目新建一个<code>MyApplication</code>类，并且继承<code>Application</code>。  </li>
</ol>
<p><em>如果你有这个类，那就直接写代码吧</em></p>
<ul>
<li>Application类代码示例<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">public class MyApp extends Application &#123;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public void onCreate() &#123;</span><br><span class="line">        super.onCreate();</span><br><span class="line"></span><br><span class="line">        /*</span><br><span class="line">        //更新 自定义初始化</span><br><span class="line">        Beta.autoInit = true;</span><br><span class="line">        //自定义 通知栏小图标</span><br><span class="line">        Beta.smallIconId = R.drawable.update1;</span><br><span class="line">        */</span><br><span class="line"></span><br><span class="line">        //bugly初始化</span><br><span class="line">        Bugly.init(getApplicationContext(), &quot;在bugly官网申请你的应用的APPID&quot;, false);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<ol start="2">
<li>在<code>AndroidMainfest.xml</code>中进行以下配置：</li>
</ol>
<ul>
<li><p>Application配置</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&lt;!--把name属性填写成你的Application类名，注意类名前边要加点--&gt;</span><br><span class="line">    &lt;application</span><br><span class="line">        android:name=&quot;.你的Application类名&quot;&gt;</span><br><span class="line">        &lt;!--这里我就省略了--&gt;</span><br><span class="line">        &lt;/application&gt;</span><br></pre></td></tr></table></figure>
</li>
<li><p>权限配置</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&lt;!--如果想在Google play发布，你需要移除READ_PHONE_STATE权限，不然可能会被下架--&gt;</span><br><span class="line">&lt;uses-permission android:name=&quot;android.permission.READ_PHONE_STATE&quot; /&gt;</span><br><span class="line">&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;</span><br><span class="line">&lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; /&gt;</span><br><span class="line">&lt;uses-permission android:name=&quot;android.permission.ACCESS_WIFI_STATE&quot; /&gt;</span><br><span class="line">&lt;uses-permission android:name=&quot;android.permission.READ_LOGS&quot; /&gt;</span><br><span class="line">&lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; /&gt;</span><br><span class="line">&lt;uses-permission android:name=&quot;android.permission.REQUEST_INSTALL_PACKAGES&quot; /&gt;</span><br></pre></td></tr></table></figure>
</li>
<li><p>Activity配置  </p>
</li>
</ul>
<p><em>添加更新弹窗的活动</em></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&lt;activity</span><br><span class="line">    android:name=&quot;com.tencent.bugly.beta.ui.BetaActivity&quot;</span><br><span class="line">    android:configChanges=&quot;keyboardHidden|orientation|screenSize|locale&quot;</span><br><span class="line">    android:theme=&quot;@android:style/Theme.Translucent&quot; /&gt;</span><br></pre></td></tr></table></figure>

<ul>
<li>配置FileProvider  </li>
</ul>
<p><em>如果您想兼容Android N或者以上的设备，必须要在AndroidManifest.xml文件中配置FileProvider来访问共享路径的文件。<br>这里要注意一下，<code>FileProvider类是在support-v4或androidx包中的</code>，检查你的工程是否引入该类库。</em></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"> &lt;provider</span><br><span class="line">    android:name=&quot;androidx.core.content.FileProvider&quot;</span><br><span class="line">    android:authorities=&quot;你的应用包名.fileProvider&quot;</span><br><span class="line">    android:exported=&quot;false&quot;</span><br><span class="line">    android:grantUriPermissions=&quot;true&quot;&gt;</span><br><span class="line">    &lt;meta-data</span><br><span class="line">        android:name=&quot;android.support.FILE_PROVIDER_PATHS&quot;</span><br><span class="line">        android:resource=&quot;@xml/provider_paths&quot;/&gt;</span><br><span class="line">&lt;/provider&gt;</span><br></pre></td></tr></table></figure>

<ul>
<li>xml/provider_paths的编写<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</span><br><span class="line">&lt;paths xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;</span><br><span class="line">    &lt;external-path name=&quot;beta_external_path&quot; path=&quot;Download/&quot;/&gt;</span><br><span class="line">    &lt;external-path name=&quot;beta_external_files_path&quot; path=&quot;Android/data/&quot;/&gt;</span><br><span class="line">&lt;/paths&gt;</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h3 id="开始测试"><a href="#开始测试" class="headerlink" title="开始测试"></a>开始测试</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">//在app里调用这句可以测试Java崩溃异常，其他异常测试方法请看图</span><br><span class="line">//如果崩溃了，那就是成功了。</span><br><span class="line">CrashReport.testJavaCrash();</span><br></pre></td></tr></table></figure>

<h3 id="结束语"><a href="#结束语" class="headerlink" title="结束语"></a>结束语</h3><p>关于bugly如何更新应用，我会在以后的文章中进行解释。</p>

        </div>

        
        <section class="post-tags">
            <div>
                <span>Tag:</span>
                <span class="tag">
                    
                    
                        <a href="/blog/tags/教程篇/">#教程篇</a>
                    
                        
                </span>
            </div>
            <div>
                <a href="javascript:window.history.back();">back</a>
            </div>
        </section>
        <section class="post-nav">
            
                <a class="prev" rel="prev" href="/blog/2021/07/07/IDM下载器提示一个假冒的序列号被用来注册/">IDM下载器提示一个假冒的序列号被用来注册</a>
            
            
            <a class="next" rel="next" href="/blog/2019/08/28/机型修改帮助文档/">机型修改帮助文档</a>
            
        </section>


    </article>
</div>

        </div>
        
    </div>
   
   </body>
</html>
